package com.ztmmm.module.qu.controller;

import com.ztmmm.common.dto.PageDto;
import com.ztmmm.common.vo.ApiRest;
import com.ztmmm.common.vo.PageResult;
import com.ztmmm.module.qu.dto.QuSaveDto;
import com.ztmmm.module.qu.entity.Qu;
import com.ztmmm.module.qu.service.IQuService;
import com.ztmmm.module.qu.service.impl.QuServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 问题题目 前端控制器
 * </p>
 *
 * @author ztm
 * @since 2023-03-21
 */
@RestController
@RequestMapping("/qu")
@CrossOrigin
@Api(description = "题目模块")
public class QuController {
    @Autowired
    private IQuService iQuService;
    @PostMapping("save")
    @ApiOperation("添加题目")
    public ApiRest save(@RequestBody QuSaveDto quSaveDto){
        return iQuService.add(quSaveDto);
    }

    @PostMapping("page")
    @ApiOperation("分页查询题目")
    public PageResult<Qu> findPage(@RequestBody PageDto<Qu> dto){
        return iQuService.findPage(dto);
    }
    @GetMapping("findOne/{qId}")
    @ApiOperation("修改时通过ID查询,返回QuSaveDto")
    public ApiRest findPage(@PathVariable String qId){
        return iQuService.selectByQid(qId);
    }

    @GetMapping("del/{qId}")
    @ApiOperation("通过quId删除题目及答案")
    public ApiRest del(@PathVariable String qId){
        return iQuService.del(qId);
    }
    @PostMapping("delAll")
    @ApiOperation("批量删除")
    public ApiRest delAll(@RequestBody String[] qId){
        return iQuService.delAll(qId);
    }
    @PostMapping("edit")
    @ApiOperation("修改,必须传所有参数")
    public ApiRest edit(@RequestBody QuSaveDto quSaveDto){
        return iQuService.edit(quSaveDto);
    }
}
